import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('createCube')
export class createCube extends Component {
    @property({ type: Prefab })
    private cube = null;
    @property
    public width: number = 5
    @property
    public height: number = 5
    start() {
        this.createCube()
    }

    update(deltaTime: number) {

    }
    createCube() {
        const temp = -this.width / 2 + 0.5
        for (let w = 0; w < this.width; w++) {
            for (let h = 0; h < this.height; h++) {

                let instance = instantiate(this.cube);
                instance.parent = this.node
                // instance.setParent(this.node);
                instance.setPosition(temp + w, h + 0.5, -0.5)
            }

        }
    }
    destroyAllChildren(){
        this.node.destroyAllChildren();
    }
}


